package com.proyecto.track.dao;

import java.util.ArrayList;

import org.hibernate.SessionFactory;

import com.proyecto.track.bo.TaskType;

public class TaskTypeDAOImp implements TaskTypeDAO{

	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	@Override
	public Long createTaskType(TaskType taskType) {
		sessionFactory.getCurrentSession().save(taskType);
		return taskType.getId();
	}

	@Override
	public Long deleteTaskType(TaskType taskType) {
		Long id = taskType.getId();
		sessionFactory.getCurrentSession().delete(taskType);
		return id;
	}

	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<TaskType> searchTaskType() {
		return (ArrayList<TaskType>)sessionFactory.getCurrentSession().createQuery("from TaskType").list();
	}

	@Override
	public TaskType searchTaskType(Long id) {
		return (TaskType) sessionFactory.getCurrentSession().get(TaskType.class, id);
	}

}
